<?php


/**
* MLT Web Engine
* http://www.molotsoft.ru
*
* @package MLT_WE
* @subpackage EEMacros
* @author Ivan Chistyakov <ivan@molotsoft.ru>
* @version $Id: make_php_esy.php 133 2009-04-06 11:47:18Z molotsoft@gmail.com $
* @link $HeadURL: http://eemacros.googlecode.com/svn/trunk/Esy/make_php_esy.php $
*/


$filename = 'php.esy';

//header('Content-Type: application/octet-stream');
//header('Content-Disposition: attachment; filename="' . $filename . '"');

$ob = ob_start();

// options
echo '; EmEditor Syntax File' . "\r\n";
echo ';' . "\r\n";
echo '#Highlight=on' . "\r\n";
echo '#BeginTag=' . "\r\n";
echo '#EndTag=' . "\r\n";
echo '#CommentBegin=/*' . "\r\n";
echo '#CommentEnd=*/' . "\r\n";
echo '#LineComment1=//' . "\r\n";
echo '#LineComment2=^#' . "\r\n";
echo '#SingleQuote=on' . "\r\n";
echo '#DoubleQuote=on' . "\r\n";
echo '#ContinueQuote=on' . "\r\n";
echo '#Escape=\\' . "\r\n";
echo '#ScriptBegin=<?' . "\r\n";
echo '#ScriptEnd=?>' . "\r\n";
echo '#SpecialSyntax=HTML-Embedded' . "\r\n";
echo '#HighlightBraces=on' . "\r\n";
echo "\r\n";

// keywords
echo '; keywords' . "\r\n";
echo ';' . "\r\n";
$keywords = array('abstract', 'and', 'array', 'as', 'break',
'case', 'catch', 'cfunction', 'class', 'clone',
'const', 'continue', 'declare', 'default', 'do',
'else', 'elseif', 'enddeclare', 'endfor', 'endforeach',
'endif', 'endswitch', 'endwhile', 'extends', 'final',
'for', 'foreach', 'function', 'global', 'goto',
'if', 'implements', 'interface', 'instanceof',
'namespace', 'new', 'old_function', 'or', 'private',
'protected', 'public', 'static', 'switch', 'throw',
'try', 'use', 'var', 'while', 'xor',
'__class__', '__dir__', '__file__', '__function__', '__method__', '__namespace__',
'die', 'echo', 'empty', 'exit', 'eval',
'include', 'include_once', 'isset', 'list', 'require',
'require_once', 'return', 'print', 'unset');
if (is_file('keywords.txt')) {
	$keywords = array_map('trim', file('keywords.txt'));
}
echo '#Keyword color=4,word=on,rightall=off,case=off,insidetag=off,regexp=off' . "\r\n";
if (!empty($keywords)) {
	echo implode("\r\n", $keywords) . "\r\n";
}
echo "\r\n";

// constants
echo '; constants' . "\r\n";
echo ';' . "\r\n";
$defined_constants = get_defined_constants(TRUE);
if (is_file('user_constants.txt')) {
	$defined_constants['user_file'] = array_flip(array_map('trim', file('user_constants.txt')));
}
echo '#Keyword color=5,word=on,rightall=off,case=off,insidetag=off,regexp=off' . "\r\n";
foreach ($defined_constants as $category => $consts) {
	if (!empty($consts)) {
		echo '; ' . $category . "\r\n";
		echo implode("\r\n", array_keys($consts)) . "\r\n";
	}
}
echo "\r\n";

// hidden functions (ioncube/zend trash)
$hidden_functions = array('_dyuweyrj4', '_dyuweyrj4r', 'cz1du', 'yldy', 'vrntfh', 'oke8', 'jq3', 'ovhsc', 'dmeqjch');
if (is_file('hidden_functions.txt')) {
	$hidden_functions = array_map('trim', file('hidden_functions.txt'));
}

// functions
echo '; functions' . "\r\n";
echo ';' . "\r\n";
$defined_functions = get_defined_functions();
if (is_file('user_functions.txt')) {
	$defined_functions['user_file'] = array_map('trim', file('user_functions.txt'));
}
echo '#Keyword color=3,word=on,rightall=off,case=off,insidetag=off,regexp=off' . "\r\n";
foreach ($defined_functions as $category => $funcs) {
	foreach ($funcs as $i => $func) {
		// exclude trash
		if (!function_exists($func) || !(bool)preg_match('~^[_a-z][a-z0-9_]*$~i', $func) || in_array($func, $hidden_functions)) {
			unset($funcs[$i]);
		}
	}
	if (!empty($funcs)) {
		echo '; ' . $category . "\r\n";
		echo implode("\r\n", $funcs) . "\r\n";
	}
}
echo "\r\n";

// classes
echo '; classes' . "\r\n";
echo ';' . "\r\n";
$declared_classes = get_declared_classes();
if (is_file('user_classes.txt')) {
	$declared_classes = array_merge($declared_classes, array_map('trim', file('user_classes.txt')));
}
echo '#Keyword color=3,word=on,rightall=off,case=off,insidetag=off,regexp=off' . "\r\n";
if (!empty($declared_classes)) {
	echo implode("\r\n", $declared_classes) . "\r\n";
}
echo "\r\n";

// interfaces
echo '; interfaces' . "\r\n";
echo ';' . "\r\n";
$declared_interfaces = get_declared_interfaces();
if (is_file('user_interfaces.txt')) {
	$declared_interfaces = array_merge($declared_interfaces, array_map('trim', file('user_interfaces.txt')));
}
echo '#Keyword color=3,word=on,rightall=off,case=off,insidetag=off,regexp=off' . "\r\n";
if (!empty($declared_interfaces)) {
	echo implode("\r\n", $declared_interfaces) . "\r\n";
}
echo "\r\n";

// variables
echo '; variables' . "\r\n";
echo ';' . "\r\n";
echo '#Keyword color=7,word=on,rightall=off,case=off,insidetag=off,regexp=on' . "\r\n";
echo '\${1,2}[_a-z][a-z0-9_]*' . "\r\n";
echo "\r\n";

if ($ob) {
	$data = ob_get_clean();
	file_put_contents($filename, $data);
	//echo $data;
}


?>